package com.rizzo.analytics.domain.errors;

import com.rizzo.infrastructure.web.validator.Save;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;

public class Error implements Serializable {

    private static final long serialVersionUID = 55L;

    @NotNull(groups = {Save.class}, message = "errors.code.field.required")
    @Size(min = 1, max = 6, message = "errors.code.field.max.length", groups = {Save.class})
    private String code;

    private double count;

    public Error() {
    }

    public Error(String code, double count) {
        this.code = code;
        this.count = count;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public double getCount() {
        return count;
    }

    public void setCount(double count) {
        this.count = count;
    }

    public void addCount(double count) {
        this.count += count;
    }

    @Override
    public boolean equals(Object o) {
        return EqualsBuilder.reflectionEquals(this, o);
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }
}
